package com.intellagric.controller.module.ift_network;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.IftNetwork;
import com.intellagric.service.iftmonitor.ift_network.NetWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/23
 * @DESC： 网络信息管理
 */
@Controller
public class NetWorkController {

    @Autowired
    private NetWorkService netWorkService;

    /**
     * 添加网络信息
     * @Param
     * @return ResponseMessage
     */
    @RequestMapping("/netword/add")
    @ResponseBody
    public ResponseMessage add(IftNetwork network) {
        network.setId(UUID.randomUUID().toString().replaceAll("-",""));
        network.setCreateDate(new Date());
        network.setUpdateDate(new Date());
        return netWorkService.addNetWork(network);
    }

    /**
     * 删除网络信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/netword/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return netWorkService.deleteNetWork(id);
    }

    /**
     * 修改网络信息
     * @Param
     * @return ResponseMessage
     */
    @RequestMapping("/netword/edit")
    @ResponseBody
    public ResponseMessage edit(IftNetwork network) {
        network.setCreateDate(null);
        network.setUpdateDate(new Date());
        return netWorkService.editNetWork(network);
    }

    /**
     * 查询网络信息
     * @return IftNetwork
     */
    @RequestMapping("/netword/{id}")
    @ResponseBody
    public IftNetwork get(@PathVariable String id) {
        return netWorkService.getNetWorkById(id);
    }

    /**
     * 查询设备的网络信息
     * @return IftNetwork
     */
    @RequestMapping("/netword/equipment/{id}")
    @ResponseBody
    public LayuiDataGridResult getByequipmentId(@PathVariable String id) {
        return netWorkService.getNetWorkByequipmentId(id);
    }

    /**
     * 查询网络信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/netword/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return netWorkService.getNetWorkList();
    }

    /**
     * 分页查询网络信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/netword/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return netWorkService.getNetWorkPage(page,limit);
    }

}
